package org.beynet.docs.session;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.List;

import javax.security.auth.login.LoginException;

import org.apache.http.client.ClientProtocolException;
import org.beynet.docs.exceptions.GDocsServerError;
import org.beynet.docs.exceptions.UnexpectedStatusCode;
import org.beynet.docs.format.Collection;
import org.beynet.docs.format.DocumentListEntry;
import org.beynet.docs.format.DocumentListFeed;

public interface Session {
    /**
     * try to authenticate into google docs system
     * @param login
     * @param password
     * @throws IOException 
     * @throws ClientProtocolException 
     */
    public void doAuthentication(String login,char[] password) throws IOException,LoginException ;
    
    /**
     * @return the auth token provided after a successful authentication
     */
    public String getAuthorizationToken();
    
    /**
     * @return the value to be used as the AuthorizationHeader
     */
    public String getAuthorizationHeaderValue() ;
    
    /**
     * fetch requested feed
     * @param url
     * @return
     * @throws IllegalStateException
     * @throws IOException
     * @throws UnexpectedStatusCode
     */
    public DocumentListFeed getFeed(URI url) throws IOException,UnexpectedStatusCode,GDocsServerError ;
    
    /**
     * fetch the requested feed entry
     * @param url
     * @return
     * @throws IOException
     */
    public DocumentListEntry getEntry(String url) throws IOException,GDocsServerError ;
    
    /**
     * return the root folder feed - ie a list of all documents and collections
     * @param session
     * @return
     * @throws IOException
     * @throws UnexpectedStatusCode
     */
    public DocumentListFeed getRootFolder(Session session) throws IOException,UnexpectedStatusCode,GDocsServerError ;
    
    /**
     * return all the collections of the current account
     * @param session
     * @return the user list of collections
     * @throws IOException 
     * @throws UnexpectedStatusCode
     */
   public List<Collection> getCollectionsAtRootLevel() throws IOException,UnexpectedStatusCode,GDocsServerError;
   
   public void getCollectionChildsOfTypeCollection(URI collection,List<Collection> result) throws IOException,UnexpectedStatusCode,GDocsServerError;
    
    /**
     * return the URI of a given URI
     * @param path : abstract path of the folder (each folder separated by a '/' )
     * @return
     * @throws IOException
     */
    public URI getDirectoryByPath(String path) throws IOException,UnexpectedStatusCode,GDocsServerError ;
    
    /**
     * create an empty folder in the destination folder
     * @param session
     * @param newFolderName
     * @param destinationFolder URI
     * @throws IOException
     * @throws GDocsServerError
     * @throws UnexpectedStatusCode 
     */
    public void createEmptyFolder(String newFolderName,URI destinationFolder) throws IOException, GDocsServerError, UnexpectedStatusCode ;
    
    /**
     * post a new file to servers
     * @param file
     * @param mimetype of the file to upload
     * @param destination
     * @return the URI of the created file
     * @throws IOException
     * @throws UnexpectedStatusCode
     */
    public URI postNewFile(File file,String mimetype,URI destination) throws IOException, UnexpectedStatusCode ;
}
